<template>
  <!-- 搜索建议 -->
  <div class="search_suggestion">
    <van-cell
      v-for="(item, index) in suggestion"
      :key="index"
      icon="search"
      :title="item"
      @click="$emit('search', item)"
    ></van-cell>
  </div>
</template>

<script>
import { getSuggestion } from "@/request/home";

export default {
  props: {
    searchText: {
      type: String,
      required: true
    }
  },
  data() {
    return { suggestion: [] };
  },
  methods: {},
  watch: {
    searchText: {
      async handler() {
        const { data } = await getSuggestion(this.searchText);
        this.suggestion = data.data.options;
        // console.log(data.data.options);
      },
      immediate: true // 该回调将会在侦听开始之后被立即调用
    }
  }
};
</script>

<style>
</style>